unit UnitUsuario;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UnitModelo, DB, StdCtrls, ImgList, ActnList, ADODB, ExtCtrls,
  ComCtrls, ToolWin, Grids, DBGrids, SMDBGrid, Mask, jpeg;

type
  TFormUsuario = class(TFormModelo)
    PERFIL: TComboBox;
    Label1: TLabel;
    LOGIN: TMaskEdit;
    Label2: TLabel;
    qryDadosUSUARIO_LOGIN: TStringField;
    qryDadosUSUARIO_NOME: TStringField;
    qryDadosUSUARIO_EMAIL: TStringField;
    qryPerfil: TADOQuery;
    qryPerfilPERFIL_CODIGO: TWordField;
    qryPerfilPERFIL_DESCRICAO: TStringField;
    qryDadosUSUARIO_SENHA: TVarBytesField;
    qryDadosPERFIL_CODIGO: TWordField;
    dsPerfil: TDataSource;
    procedure qryPerfilAfterOpen(DataSet: TDataSet);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure actNovoExecute(Sender: TObject);
    procedure actAlterarExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormUsuario: TFormUsuario;

implementation

uses UnitCadUsuario, UnitPrincipal;

{$R *.dfm}

procedure TFormUsuario.qryPerfilAfterOpen(DataSet: TDataSet);
begin
  inherited;
  PERFIL.Clear;
  PERFIL.Items.Add('');
  with qryPerfil do
  begin
    Open;
    while not eof do
    begin
      PERFIL.Items.Add(Fields[0].AsString);
      Next;
    end;
    PERFIL.ItemIndex := 0;
  end;

end;

procedure TFormUsuario.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  qryPerfil.Close;
  FormUsuario := nil;
end;

procedure TFormUsuario.actNovoExecute(Sender: TObject);
begin
  inherited;
  qryDados.Insert;
  if FormCadUsuario = nil then
    FormCadUsuario := TFormCadUsuario.Create(Self);
  FormCadUsuario.mskSenha.Enabled     := True;
  FormCadUsuario.mskConfirma.Enabled  := True;
  FormCadUsuario.ShowModal;
end;

procedure TFormUsuario.actAlterarExecute(Sender: TObject);
begin
  inherited;
  qryDados.Edit;
  if FormCadUsuario = nil then
    FormCadUsuario := TFormCadUsuario.Create(Self);
  FormCadUsuario.mskSenha.Enabled     := False;
  FormCadUsuario.mskConfirma.Enabled  := False;
  FormCadUsuario.ShowModal;
end;

procedure TFormUsuario.FormCreate(Sender: TObject);
begin
  inherited;
  qryPerfil.Open;
end;

end.
